<?php

class BGoodsSlideShow extends BaseModel
{
    protected $res;
    protected $redis_key = "admin_";

    public function getSource()
    {
        return "f_b_goods_slideshow";
    }

    public function initialize()
    {
        parent::initialize();
    }

    /**
     * @func 获取详情
     * @param $id
     * @param $switch
     * @return Mixed
     */
    public function find_by_id($id, $switch = false)
    {
        if (empty($id)) {
            return [];
        }
        $info = $this->findFirstById($id);
        if ($switch) {
            return $info;
        }
        if ($info) {
            return $info->toarray();
        } else {
            return [];
        }
    }

    public function slideshow_list($params = [])
    {
        $page = intval($params['page']);
        $size = intval($params['limit']);
        if ($page > 0) {
            $page = ($page - 1) * $size;
        }
        $condition = '1=1 ';
        if (isset($params['keywords']) && !empty($params['keywords'])) {
            $condition .= " and name like '%{$params['keywords']}%'";
        }
        $cate_list = $this::find(
            array(
                $condition,
                "order"  => 'id desc',
                //                "columns" => 'id,cid,item_id,title,short_title,shop_type,pic_logo,coupon_money,price,end_price,month_sale,site,created_at,updated_at,top,status',
                'limit'  => $size,
                'offset' => $page
            ));
//        //直接获取最后一条sql语句
//        echo $this->di->get('profiler')->getLastProfile()->getSQLStatement();
//        exit;

        return $cate_list;
    }

    public function slideshow_count($params = [])
    {

        $condition = '1=1 ';
        if (isset($params['keywords']) && !empty($params['keywords'])) {
            $condition .= " and name like '%{$params['keywords']}%'";
        }
        $cate_list = $this::count(
            array(
                $condition,
                "columns" => 'id',
            ));

        return $cate_list;
    }

    public function save_params($params)
    {
        $result = $this::save($params);
        return $result;
    }

}
